// tspcluster - Traveling Salesman Problem
// Copyright (C) 2006  Frederik Carlier
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

using System;
using System.Collections.Generic;
using System.Text;

namespace UGent.Tsp
{
    static class VectorMath
    {
        public static void Log(double[] vector)
        {
            Log(vector, false);
        }

        public static void Log(double[] vector, bool preserveZero)
        {
            int dimension = vector.Length;

            for (int i = 0; i < dimension; i++)
            {
                // If the vector element is zero, in theory
                // the log returns minus infinity.
                // However, if preserveZero is set, we just keep
                // the zero, pretending that the value was 1
                // (log 1 = 0)
                if (!(preserveZero && vector[i] == 0))
                    vector[i] = Math.Log(vector[i]);
            }
        }

        public static void Exp(double[] vector)
        {
            int dimension = vector.Length;

            for (int i = 0; i < dimension; i++)
            {
                vector[i] = Math.Exp(vector[i]);
            }
        }
    }
}
